Repository navigation
feat(core): rate more destructive commands red and add secret paths - #1732
smart-ssh-coder[bot] wants to merge 9 commits into
Conversation
…1725) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Review
Verdict: needs maintainer
Review level: elevated
One requirement line conflicts with an acceptance criterion: SQL drop …/truncate table must be red "anywhere in the command", but grep -i "drop table" migrations.sql must keep its rating. The PR settles this by requiring one of 14 SQL client words in the same command. That narrows a requirement in the risk classifier, so the maintainer decides how it should be narrowed (question in the issue). The blocking points below are independent of that decision and should be fixed in the same round.
Blocking
crates/core/src/risk/patterns.rs:334-341(SQL_DESTRUCTIVE) — narrows a requirement, and the narrowing is not recorded. Requirement: red "anywhere in the command". Built: red only together with a client word from a fixed list. Not covered, though they drop data (executed by the functional reviewer):mysqlsh -e "drop database x",cockroach sql -e "drop database x",trino --execute 'drop table x',beeline -e 'drop table x',sqlite app.db 'drop table t'. Red, though they are searches:grep -i 'drop table' mysql.log. Waiting for the maintainer's decision. Once it is made, record the chosen rule, its scope and the known gaps in an ADR (AGENTS.md, "ADRs": a call the issue left open, especially a scope reduction), and make the spec 0026 sentence describe the rule rather than promise an outcome (see Non-blocking).crates/core/src/risk/patterns.rs:473(sgdisk) —sgdisk -oZ /dev/sda/sgdisk -Zo /dev/sda(zap plus a new GPT, a common idiom) → None (executed by the functional reviewer). sgdisk uses popt, which accepts grouped short options. The requirement names-Z. Fix: matchzinside a short-option group, e.g.-[a-z]*z[a-z]*(?:\s|$), as thetruncatepattern already does for-s. Add a test.crates/core/src/risk/patterns.rs:506(dd) —dd "of=/dev/sdb" if=/tmp/imganddd of='/dev/sdb' if=…→ None. Server-risk patterns run on the lowercased segment without quote stripping (classifier.rs:60-62, read). The new regex needs whitespace right beforeof=, and the old glob needsif=first. The requirement says "regardless of argument order". Fix:^(?:\S*/)?dd\s(?:.*[\s'"])?of=['"]?/dev/. Add a test.crates/core/src/risk/patterns.rs:456(truncate) —truncate --siz=0 /var/lib/mysql/ibdata1(GNU getopt_long accepts any unique prefix of a long option) → None (executed by the functional reviewer). Fix:--s(?:i(?:z(?:e)?)?)?(?:[=\s]|$). Add a test.crates/core/src/risk/patterns.rs:489(lvremove/vgremove/pvremove) —lvm lvremove -f vg/data(alsolvm vgremove,lvm pvremove) → None (read: the pattern is anchored to the command word, andlvmis not a wrapper that gets unwrapped). Fix: allow an optional(?:\S*/)?lvm\s+before the subcommand. Add a test.crates/core/src/risk/patterns.rs:269-272— the newcredentials\.tfrc\.jsonentry never takes effect.secret_path_patterns()uses the first match (classifier.rs:409, read), and the generic\bcredentials\bat:212already matchescredentials.tfrc.json. So the Terraform reason text is never shown. Clean shape: move the entry above\bcredentials\b, as the file already does with\.aws/credentials.crates/core/src/risk/patterns.rs:316-319— inSECRET_PATH_HINTS,application_default_credentials,legacy_credentialsandcredentials.tfrcare redundant. The list is checked withcontains, and"credentials"(:301) is already in it. Clean shape: drop the three entries.crates/core/src/risk/patterns.rs:336-341—SQL_DESTRUCTIVEwrites out the 14-client list and the statement list twice each, once per order, so the copies can drift apart. Clean shape: onemacro_rules!fragment per list, as the file already does withssh_key_end!/ssh_identity_key!, joined for both orders withconcat!. This depends on the SQL decision above.crates/core/src/risk/patterns.rs:565—#[allow(clippy::too_many_lines)]differs from the crate's convention for production code. Use#[expect(clippy::too_many_lines, reason = "flat pattern table")], as infilter/engine.rs:574andai/redactor.rs:285.
Non-blocking
docs/specs/0026-command-risk-indicators.md:82-83— "ein bloßesgrep "drop table"bleibt unbewertet" promises an outcome. With the client-word rule,grep -i "drop table" mysql-migrations.sqlis red. Describe the rule instead (adjust after the decision).patterns.rszfs/zpool/truncate/findregexes:(?:.*\s)?reaches across segments when the whole command is matched. As a result,zfs list | grep destroy,zpool status && echo destroyandtruncate --help; ls -sare now red (executed by the functional reviewer; None on the base). This is stricter only, but it adds confirmations.[^;&|]*instead of.*would keep each match inside one segment.patterns.rs:136, :250, :312, :687— the bare// Issue #1725markers say nothing about the entries below them. Describe what they cover (e.g. "Cloud/IaC credential stores and password databases").
Verified
- criteria: AC1–AC8 met as tested. All 14 families plus the SQL forms are each tested plain, behind
sudo, inbash -cand chained.dd of=/dev/sdb if=/tmp/imgis red. The near misses are pinned at None, which is today's level (the test passed against the basepatterns.rs). The five secret reads escalate and rate the data axis red. An allow rule still ends inFILTER_RED_RISK_REQUIRES_CONFIRM/FILTER_SECRET_PATH_READ_REQUIRES_CONFIRM(executed:cargo test -p ssh-manager-core --lib risk,cargo test -p app-logic --lib red_risk). AC3 rests on the SQL narrowing above. - counter-proof: with
crates/core/src/risk/patterns.rsreset toorigin/develop, the three new positive core tests and both new app-logic pipeline tests went red. The near-miss tests stayed green, which is correct because they pin the base level. Green again after the restore (executed by the functional reviewer). - edge cases: wrappers
nice/env/xargs/timeout/nohup/busybox/doas/sudo -u root/$( )/sh -c→ red, ok. Path-qualifiedpsql,docker exec … psql,kubectl exec … -- psql→ red, ok.drop tablewith several spaces or a tab,drop table if exists→ red, ok.truncate --size 0,truncate -s +10→ red, ok.dd of=/dev/null if=/dev/zero→ red, the same level as the base already gaveif=first.cat ~/.S3CFG,less prod.tfstate.backup→ secret path and data axis red, ok. sgdisk groups, quoteddd of=,truncate --siz=andlvm lvremove→ findings (executed: temporary probe test, removed again). - callers checked:
server_risk_patterns/data_risk_patterns/secret_path_patternsand theSECRET_*lists are used only inclassifier.rs→ ok. Entries were only added (read). - tests run locally:
cargo test --locked -p ssh-manager-core --lib risk→ 154 passed.cargo test --locked -p app-logic --lib red_risk→ 32 passed.cargo test --locked -p ssh-manager-core --lib filter→ 263 passed, 1 ignored (executed). - UI: not a UI change
- data: not touched
- CI: all checks green on
dac5cae8.
Timing analysis
- 2 test files analysed: no timing dependency found.
tests_destructive_families.rsonly classifies strings. The pipeline tests use a mock transport, and their 5 s timeout only guards against a hang.
Coherence
- comments: all checked match the code (the wrapper/segment note, the SQL pipe note, "the glob above only knows
if=first"). The bare// Issue #1725markers → non-blocking. - fit:
patterns.rs:269deadcredentials.tfrc.jsonentry,:316-319redundant hints,:336-341duplicated lists,:565allowinstead ofexpect→ blocking (in-scope, clean shapes above). Rejected: the suggestion to merge the newddregex with the existing*dd*if=**of=/dev/*glob. Replacing the unanchored glob with an anchored regex would narrow an existing pattern, which the issue forbids.
Spec and boundary
- visible behaviour changed: red server risk for the new destructive families and for SQL drop/truncate with a client word. Reads of the new secret paths escalate, and five of them rate the data axis red.
- spec searched (
risiko|risk|secret-pfad|destructive, family names), spec covering it: 0026 "Beispiele Server-Risiko"/"Beispiele Daten-Risiko", 0068 part 2 - verdict: the spec change is present and matches the code. The wording of the SQL sentence → non-blocking. The ADR for the SQL rule is missing → blocking (above).
- boundary, CI changes, vendor: ok. The changelog fragment is English, under
### Security, and describes the user-visible effect. No CI changes.
Security checks
- no loosening (the diff only adds entries; filter engine, hard blacklist and rule matching untouched), escalation only (
best_matchkeeps the highest level), fail-open (a regex that fails to compile never matches, and every new regex has a positive test), ReDoS/panic (linear-timeregex, length cap before parsing), confirmation despite an allow rule (tested through the pipeline). The "Threat model: no change" note holds: THREAT-MODEL.md §6 calls the lists starting points. - security review (subagent): 10 bypass attempts, no loosening.
truncate --siz=0→ blocking (confirmed)- quoted
dd "of=/dev/sdb"→ blocking (confirmed) lvm lvremove→ blocking (confirmed)sgdisk -Zo→ blocking (confirmed by the functional reviewer's run)TRUNCATE orderswithoutTABLE,DROP/**/DATABASE,mysqladmin drop/dropdb→ part of the SQL decision. Not in the issue's wording, so a follow-up unless the decision covers them.find … -exec shred {} +/-exec wipefs→ non-blocking.-execarguments are not unwrapped, and the issue does not list this form. Follow-up.grep -r token ~/.azure(no trailing slash) → non-blocking, unsure. The issue writes.azure/. Follow-up.- quoting inside arguments (
zfs 'destroy' tank) → non-blocking. The existing patterns have the same limitation.
UI review
- not a UI change
Follow-ups
- Unwrap
find -exec/-execdir(andxargs-style) arguments for the new destructive families (find … -exec shred {} +). - Rate SQL forms outside the issue's wording:
TRUNCATE <table>withoutTABLE, SQL comments between keywords,mysqladmin drop,dropdb,psql -f <file>. Covered by the maintainer's decision, or else separate work. - Match
~/.azureandlegacy_credentialswithout a trailing slash (directory arguments togrep -r/tar). - Keep the multi-word regexes inside one segment, so that
zfs list | grep destroyis not red.
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated
The head (dac5cae8) is the same commit as in the previous review. It was written before the maintainer decided the SQL question, so it does not yet implement that decision. The maintainer chose option 2 in the issue thread:
Rate destructive SQL statements (drop database / drop schema / drop table, truncate table) red wherever they appear in the command, except when the first command word of the segment is a search or read tool (grep, rg, ag, less, more, cat, head, tail, sed -n, awk and similar). Commands that only mention such a statement (for example
echointo a file orgit commit -m "drop table …") asking for confirmation is accepted. Pipes into a client such asecho "drop table t" | psqlstay red. The other review points (sgdisk grouped flags, quoteddd "of=/dev/…",truncate --siz=,lvm lvremove, code-shape points) are fixed in the same round.
This was a full round, and every reviewer checked the code again.
Blocking
-
crates/core/src/risk/patterns.rs:334-341, :509-519(SQL_DESTRUCTIVE) — the maintainer's decision (option 2) is not implemented. The pattern still needs one of 14 SQL client words. Results at head (executed):- Not rated:
mysqlsh -e "drop database x",cockroach sql -e "drop database x",beeline -e 'drop table x',trino --execute 'drop table x',sqlite app.db 'drop table t',git commit -m "drop table users",echo 'drop table t' > m.sql. - Red, but grep is the first word:
grep -i 'drop table' mysql.log.
Fix:
- Match
drop\s+(database|schema|table)/truncate\s+tableanywhere in the command. - Skip only a segment whose first command word, after sudo/wrapper resolution, is a search or read tool (grep, egrep, rg, ag, less, more, cat, head, tail,
sed -n, awk, …). - Apply the skip per segment, so that
grep x f | psqlandecho "drop table t" | psqlstay red. Watch out: the classifier also matches the whole command, and that whole-command match must not undo the per-segment skip. - Rewrite the comments at
:334-335and:510-514, which describe the rejected client-word rule. - Pin these in
tests_destructive_families.rs:- an unlisted client (
mysqlsh) → Red git commit -m "drop table x"→ Redecho "drop table t" | psql→ Redgrep x f | psql -c "drop table t"→ Red- each listed read tool with the statement → keeps today's level, including
grep -i "drop table" migrations.sqlandgrep -i 'drop table' mysql.log
- an unlisted client (
- Not rated:
-
docs/specs/0026-command-risk-indicators.md:81-83— the spec describes the client-word rule ("in einem Kommando mit SQL-Client …"). Describe the decided rule instead:- red anywhere in the command;
- not rated when the segment's first command word is a search or read tool;
- commands that only mention such a statement also ask for confirmation;
- a pipe into a client stays red.
-
ADR missing (AGENTS.md, "ADRs": a call the issue left open). Record:
- the SQL rule from the decision;
- which tools count as "search or read tools" (the decision says "and similar", so the list you pick is your call and must be written down);
- the accepted false positives;
- the
find -deletechoice (a regex anchored to thefindcommand word).
The next free number on
developis 0166; check it against other open PRs. -
crates/core/src/risk/patterns.rs:473(sgdisk) —sgdisk -Zo /dev/sdaandsgdisk -oZ /dev/sda→ None (executed). sgdisk accepts grouped short options. Fix: matchzinside a short-option group, e.g.\s-[a-z]*z[a-z]*(?:\s|$). Add a test. -
crates/core/src/risk/patterns.rs:506(dd) —dd "of=/dev/sda" if=/tmp/xanddd 'of=/dev/sda' if=/tmp/x→ None (executed). Requirement: "regardless of argument order". Fix:^(?:\S*/)?dd\s(?:.*[\s'"])?of=['"]?/dev/. Add a test. -
crates/core/src/risk/patterns.rs:456(truncate) — two misses (executed or read):truncate --siz=0 fandtruncate --si 0 f→ None. GNU getopt_long accepts unique prefixes of long options.truncate -s-1G /var/lib/mysql/ibdata1→ None. This is a shrink, with the value attached to-s. The(?:[^a-z-]|$)after-sexcludes-.
Fix:
--s(?:i(?:ze?)?)?(?:[=\s]|$)for the long form, and allow-right after the shorts. Add a test for each. -
crates/core/src/risk/patterns.rs:~489(lvremove/vgremove/pvremove) —lvm lvremove -f vg/dataandlvm vgremove vg→ None (executed).lvmis not a resolved wrapper. Fix: allow an optional(?:\S*/)?lvm\s+before the subcommand. Add a test. -
crates/core/src/risk/patterns.rs:262-272— the newcredentials\.tfrc\.jsonentry never takes effect, because the first match wins and the generic\bcredentials\bat:213already matches it. Clean shape: move the entry above\bcredentials\b, as the file already does with\.aws/credentials. -
crates/core/src/risk/patterns.rs:316-318—application_default_credentials,legacy_credentialsandcredentials.tfrcinSECRET_PATH_HINTSare redundant. The list is checked withcontains, and"credentials"is already in it. Clean shape: drop the three entries. -
crates/core/src/risk/patterns.rs:565— this PR adds#[allow(clippy::too_many_lines)]. The crate uses#[expect(clippy::too_many_lines, reason = "…")](filter/engine.rs:574,profiles/ssh_config/plan.rs:319). Use that form. -
crates/core/src/risk/patterns.rs:439-441— the comment says "Each regex is anchored to the command word". After item 1, the SQL entry is deliberately not anchored to a command word. Reword the comment so it matches the code. -
PR description — "Summary" ("SQL drop/truncate with a SQL client") and "Assumptions" (client-word rule) contradict the decision. Update both with the code.
Non-blocking
patterns.rs:136, :250, :312, :687— the bare// Issue #1725markers do not say what the entries below them cover. Describe them, e.g. "Terraform state, KeePass databases and cloud-CLI credential files (issue #1725)".patterns.rszfs/zpool/truncate/find regexes —(?:.*\s)?can reach across segments when the whole command is matched, and the subcommand position is not checked. Sozfs list | grep destroy,zpool status destroyandtruncate --help; ls -sare red. This is stricter only. Using[^;&|]*instead of.*would keep each match inside one segment.patterns.rs:506— fordd if=/dev/zero of=/dev/sdathe shown reason changes from the old text to the new one.best_matchkeeps the last equal maximum. The rating does not change.changelog.d/issue-1725-…md— once item 1 is done, it would be more honest to mention that commands that merely mention such SQL also ask for confirmation.
Verified
- criteria at head:
- AC1 is met for the listed forms, but not for SQL "anywhere" or the four forms in items 4–7.
- AC2 and AC3 are met.
- AC4 is pinned at None, which is today's level (green on base).
- AC5 and AC6 are met.
- AC7 and AC8 are green.
- (executed:
cargo test -q --locked -p ssh-manager-core --lib risk,cargo test -q --locked -p app-logic --lib red_risk)
- counter-proof: with
crates/core/src/risk/patterns.rsreset toorigin/develop, the three positive core tests and both app-logic pipeline tests went red. They went green again after the restore (executed by the functional reviewer). - edge cases:
- Red as expected:
find . -name x -delete -print,truncate --size 0/-cs0/-s+0,nice shred x,timeout 5 wipefs -a /dev/sdb,xargs shred < list,sgdisk -p /dev/sda -z. Secret reads of.tfstate.backup,~/.azure/config,legacy_credentialsandcredentials.tfrc.jsonescalate. - Not red, as expected:
grep -- -delete notes.txt,find . -name '*-delete*',ls terraform.tfstate.d,cat kdbx.md. - Not red, but should be → findings 1, 4–7.
- (executed: temporary probe test, removed again)
- Red as expected:
- callers checked:
server_risk_patterns,data_risk_patterns,secret_path_patterns,SECRET_PATH_HINTSand the candidate lists are used only inclassifier.rsand the risk tests → ok (read). - tests run locally:
cargo test -q --locked -p ssh-manager-core --lib risk→ 154 passed;cargo test -q --locked -p app-logic --lib red_risk→ 32 passed (executed). - UI: not a UI change
- data: not touched
- CI: all checks green on
dac5cae8(executed:wait-ci 1732).
Timing analysis
- 2 test files analysed: no timing dependency found. The classifier tests are synchronous. The pipeline tests use a mock transport, and their 5 s timeout only guards against a hang.
Coherence
- comments: 9 comments checked.
- The SQL comments at
:334-335and:510-514describe the rejected rule → blocking (item 1). :439"each regex is anchored" → blocking (item 11).- The bare issue markers → non-blocking.
- The SQL comments at
- fit:
- Dead
credentials.tfrc.jsonentry, redundant hints,allowinstead ofexpect→ blocking (items 8–10). - The doubled client list in
SQL_DESTRUCTIVE(:336-341) goes away with item 1. If client lists stay in some form, keep each list in one place.
- Dead
Spec and boundary
- visible behaviour changed:
- red server risk for the new destructive families and for SQL drop/truncate;
- reads of the new secret paths escalate;
- five of them rate the data axis red.
- spec searched (
drop table|shred|wipefs|tfstate|secret-pfad|server-risiko), spec covering it: 0026 (server and data risk examples), 0068 part 2 (secret paths), 0092 (red needs confirmation, unchanged). - verdict: the 0026 SQL sentence contradicts the maintainer's decision → blocking (item 2). The ADR is missing → blocking (item 3). The 0068 list and the 0026 data-risk list match the code.
- boundary, CI changes, vendor: ok. Texts are English; the German reason texts follow the existing entries. No CI changes.
Security checks
- Checked:
- escalation only, no loosening against
origin/develop(only additions); crates/core/src/filter/, hard blacklist and rule matching untouched;- an allow rule still ends in a confirmation (pipeline tests);
- no ReDoS (linear
regexcrate). - The "Threat model: no change" note holds (THREAT-MODEL.md §6 calls the lists starting points).
- escalation only, no loosening against
- security review (subagent): 12 bypass attempts, no loosening.
- SQL client-word rule (
mysqlsh,sqlite,cockroach sql) → blocking (confirmed, item 1) sgdisk -Zo→ blocking (confirmed, item 4)- quoted
dd "of=/dev/sdb"→ blocking (confirmed, item 5). The hard blacklist still denies this input, so only the risk axis is affected. truncate --siz=,truncate -s-1G→ blocking (confirmed, item 6)lvm lvremove→ blocking (confirmed, item 7)- quoted flag tokens on the other new families (
find /srv "-delete",zfs 'destroy' tank,sgdisk "--zap-all",truncate "-s" 0 f) → non-blocking, unsure. Arguments keep their quotes, and existing patterns share this limitation. The issue only names the quotedddform. Follow-up. mysql -e "drop/**/table t",TRUNCATE orderswithoutTABLE→ non-blocking, unsure. Outside the issue's wording and the decision. Follow-up.truncate -r/--reference→ non-blocking, unsure. Not in the issue's list. Follow-up.
- SQL client-word rule (
UI review
- not a UI change
Previous findings
- SQL client-word rule → still open; the decision is now made (item 1, ADR item 3, spec item 2)
- sgdisk grouped flags → still open (item 4)
- quoted
dd of=→ still open (item 5) truncate --siz=→ still open (item 6)lvm lvremove→ still open (item 7)- dead
credentials.tfrc.jsonentry → still open (item 8) - redundant hints → still open (item 9)
- duplicated client lists → goes away with item 1
allow→expect→ still open (item 10)
Follow-ups
- Unwrap
find -exec/-execdirarguments for the destructive families (find … -exec shred {} +). - Quoted flag tokens on the argument-keyed families (
find /srv "-delete",zfs 'destroy' tank,sgdisk "--zap-all"): also try an argument-unquoted variant of each segment (escalation only). - SQL forms outside the issue's wording:
TRUNCATE <table>withoutTABLE, SQL comments between keywords,mysqladmin drop,dropdb,psql -f <file>. truncate -r/--reference.- Match
~/.azureandlegacy_credentialswithout a trailing slash (directory arguments togrep -r/tar). - Keep the multi-word regexes inside one segment (
zfs list | grep destroyshould not be red).
|
Review round: 1 SQL rule per decision (anywhere, exempt per segment by first word; spec 0026 + ADR 0167), 2-3 done, 4-7 fixed with tests, 8-9 done, 10 the exception is gone (data pattern table split instead), 11 comment fixed, 12 PR body updated. CI green. |
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated
Follow-up round: this round checks the delta dac5cae8..964776b0. The maintainer's decision (option 2) is implemented. Spec 0026 and ADR 0167 describe it, and items 1–4 and 7–12 of the last review are fixed. Three gaps remain. One comes from the new read-tool exemption: a read tool that feeds the statement into a client is exempt. The other two are partial fixes of items 5 and 6.
Blocking
-
crates/core/src/risk/classifier.rs:227-239(destructive_sql) /patterns.rs:344(SQL_READ_TOOL). A read-tool segment that pipes the statement into a client is exempt, so the whole command gets no rating. Executed at head:cat <<< "drop table users" | psql→ Noneawk 'BEGIN{print "drop table t"}' | psql→ None
In every variant the classifier sees, the segment holding the statement starts with
cat/awk, and the barepsqlsegment holds no statement. With allow rules forcat *andpsql *, the command runs without a confirmation. This contradicts two things:- the maintainer's decision: "Pipes into a client such as
echo "drop table t" | psqlstay red".cat <<< … | psqlis the same thing. - the issue's requirement: "covers … here-strings".
psql <<< "drop table t"is red,cat <<< "drop table t" | psqlis not.
Both commands were red at
dac5cae8. Fix: exempt a read-tool segment only when its output is not piped into a segment whose first word is not a read tool. Simpler alternative: exempt only when every pipeline segment of the command is a read tool.grep -i "drop table" migrations.sqlandgrep … | lessstay unrated either way. Add both commands above as Red totests_destructive_families.rs, and add a sentence to ADR 0167 and Spec 0026: a read tool whose output goes into another program is not exempt. -
crates/core/src/risk/patterns.rs:518(dd). Item 5 is only half fixed. The regex allows a quote beforeof=but not after it. These are rated None (read, and traced by the functional and security reviewers):dd of="/dev/sda" if=xdd of='/dev/sda'dd if=x of="/dev/sda"
The shell removes the quotes, so dd writes to the device. Fix:
["']?of=["']?/dev/, as proposed last round. Add test entries. -
crates/core/src/risk/patterns.rs:467(truncate). Item 6 is only half fixed. The long form starts at--si, sotruncate --s=0 /var/log/syslogandtruncate --s 0 f→ None (executed). GNU truncate accepts--sas--size. The functional reviewer ran it, and the file was emptied. Fix:--s(?:i(?:ze?)?)?, as proposed last round. Add test entries.
Non-blocking
-
patterns.rs:345:awk/gawk/sed -ncan run commands themselves, and all of these rate None:awk 'BEGIN{system("psql -c \"drop table t\"")}'sed -n '1e psql -c "drop table t"' fack --pager='psql -c "drop table t"' x
ADR 0167 records the awk/sed form as an accepted false negative, and the decision lists awk and
sed -n. A possible tightening: do not exempt a segment withsystem(, a sedecommand or--pager. -
tests_destructive_families.rs:122: no test pins the reason text forcredentials.tfrc.json. The test checks onlyis_some(). Item 8 is fixed: the reason shown is the Terraform one (probed by the functional reviewer). -
patterns.rs:136, :255, :686: the bare// Issue #1725markers are still there. Only:313got a description. -
PR description: "Summary" still says
#[expect], but the table was split instead. A test note sits after the attribution line. -
changelog.d/issue-1725-…md: you could mention that commands which only mention such SQL now also ask for confirmation.
Verified
- criteria: AC1 is met except for the forms in blocking items 2 and 3. AC2–AC6 are met. AC7 and AC8 are green. The maintainer's option 2 is implemented per segment, the read-tool check runs on the sudo/wrapper-resolved form, and the required tests are present (
mysqlsh,git commit -m,echo … | psql,grep x f | psql -c …→ Red). The gap is in blocking item 1. (executed:cargo test --locked -q -p ssh-manager-core --lib risk,-p app-logic --lib red_risk) - counter-proof: the new tests fail with
classifier.rs/patterns.rsfromdac5cae8. Forcing the read-tool check to "not exempt" makesnear_misses_keep_their_ratingfail. Removing the sudo resolution from that check makessudo grep …fail. All green after restoring (executed by the functional reviewer). - edge cases:
- Exempt as expected:
sudo/env/nice/timeout/FOO=1//usr/bin/grep/"grep"→ None, ok. - Red as expected:
- chains:
;,&&,||,&,|& - substitutions:
$(…), backticks,<(…) - remote and container:
ssh host psql,docker exec,kubectl exec sedwithout-n,DROP/**/DATABASE, a tab in the statement,IF EXISTS
- chains:
bash -c "grep 'drop table' f"→ Red, accepted in ADR 0167.sgdisk -Zo/-oZ/-o -Z,lvm lvremove/sudo lvm lvremove→ Red;lvm lvs→ None.cat <<< … | psql,awk print | psql,dd of="/dev/…",truncate --s→ findings. (executed: throwaway probe outside the tree, and my own probe in a separate worktree, removed)
- Exempt as expected:
- callers checked:
destructive_sql(1 call site),data_risk_patterns()(classifier and 2 test sites; theptr::eqdebug assert still holds),SECRET_PATH_HINTS(3 sites) → ok (read). - tests run locally (executed by the functional reviewer):
cargo test --locked -q -p ssh-manager-core→ 936 + 10 passed--lib filter→ 263 passed, 1 ignored-p app-logic --lib red_risk→ 32 passednode scripts/check-file-size.mjs→ ok
- UI: not a UI change
- data: not touched
- CI: all checks green on
964776b0(executed:gh pr checks 1732).
Timing analysis
- 1 test file in the delta analysed (
tests_destructive_families.rs;tests_red_risk.rsunchanged): no timing dependency found. The tests are synchronous, string-only classifier calls.
Coherence
- comments: the SQL comments and the
patterns.rs:449table comment now match the code. The bare markers → non-blocking. - fit:
destructive_sqlfits next toglob_reads_private_key: an escalate-only step with a fixed reason, and constants inpatterns.rs. The red/yellow split of the data table follows the existing section boundary and replaces the lint exception. The change fits.
Spec and boundary
- visible behaviour changed: red server risk for the new families and for destructive SQL anywhere except in read-tool segments; new secret paths, five with the data axis red.
- spec searched (
risiko|risk|destruktiv|drop table|secret-pfad), spec covering it: 0026 "Beispiele Server-Risiko"/"Beispiele Daten-Risiko", 0068 part 2. - verdict: the spec change is present and matches the code. After blocking item 1, add the sentence about read tools that feed another program. ADR 0167 is free: 0166 is taken by open PR #1755. The ADR records the rule, the read-tool list, the accepted false positives/negatives and the
find -deletechoice. INDEX row ok. - boundary, CI changes, vendor: ok. Texts are in English, no CI changes. Neighbour PR #1733 (back-merge touching
patterns.rs): the PR is currently mergeable.
Security checks
- Checked:
- Escalation only:
destructive_sqlraises the rating only below Red. - Nothing narrowed against
origin/develop. The server and secret-path entries were compared one by one, and the split data table is identical to the base in content and order. best_matchis unchanged, and nothing undercrates/core/src/filter/changed.- Red still asks for confirmation despite an allow rule (pipeline tests).
- The "Threat model: no change" note holds.
- Escalation only:
- security review (subagent): 14 bypass attempts, no loosening against the base.
cat <<< "drop table …" | psql,awk 'BEGIN{print …}' | psql→ blocking (confirmed, item 1)truncate --s=0/--s 0→ blocking (confirmed, item 3)- awk
system(), sede,ack --pager→ non-blocking (ADR 0167 accepts awk/sed). Follow-up. - quote splitting inside arguments (
psql -c 'drop'' table t',zfs "destroy" tank,find /x '-delete',dd of=//dev/sdb) → non-blocking, unsure. Existing patterns share this limitation, and the quoteddd of="/dev/…"form is blocking item 2. Follow-up. truncate -r /dev/null f(--reference) → non-blocking, not in the issue's list. Follow-up.
UI review
- not a UI change
Previous findings
- SQL option 2 → fixed in 0639fb7, but a new gap (blocking item 1)
- Spec 0026 → fixed in 0639fb7
- ADR → fixed (ADR 0167)
- sgdisk grouped flags → fixed
- quoted
dd→ partly fixed (blocking item 2) - truncate
--siz/--si/-s-1G→ partly fixed (blocking item 3) lvm lvremove→ fixedcredentials.tfrc.jsonorder → fixed- redundant hints → fixed
allow→expect→ resolved by splitting the table (06d24cc)- "each regex is anchored" comment → fixed
- PR description → fixed, apart from the
#[expect]mention (non-blocking)
Follow-ups
- A command substitution inside a here-string is never classified. On
origin/developalready,grep x <<< "$(reboot)"/"$(shred /dev/sda)"→ None. - Quoted or split flag tokens on the argument-keyed families: also try a dequoted copy of each segment (escalation only).
- awk
system(), sede,ack --pagerin read-tool segments. - SQL forms outside the issue:
TRUNCATE <table>withoutTABLE,mysqladmin drop,dropdb,drop materialized view, statements built at run time. truncate -r/--reference;find -exec shred {} +;~/.azure/legacy_credentialswithout a trailing slash.- Keep the multi-word regexes inside one segment (
zfs list | grep destroy).
…ructive (#1725) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…-destructive Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ed (#1725) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Review points of 964776b addressed: (1) a read-tool stage that holds the statement and pipes into a non-read-tool stage is now red ( |
Closes #1725
Summary
Adds red server-risk patterns for more destructive families (shred, wipefs, truncate -s, find -delete, blkdiscard, sgdisk zap, mke2fs, mkswap, lv/vg/pvremove, zpool/zfs destroy,
dd of=/dev/…in any order, SQL drop/truncate anywhere in a command except in search/read-tool segments) and secret paths (.tfstate, .kdbx, .s3cfg, .azure/, application_default_credentials.json, legacy_credentials/, credentials.tfrc.json). Review round: alsosgdisk -Zo/-oZ,dd "of=/dev/…",truncate --siz=/--si/-s-1G,lvm lvremove/vgremove/pvremove(each with a test intests_destructive_families.rs:each_family_is_red_plain_sudo_wrapped_and_chained),credentials.tfrc.jsonentry ordered before the generic one, redundant hints dropped,#[expect].Acceptance Criteria
bash -c, chained: met —tests_destructive_families.rs:each_family_is_red_plain_sudo_wrapped_and_chaineddd of=/dev/sdb if=/tmp/imgred: met — same test (list entry)mysql -e "DROP DATABASE shop",psql -c "truncate table orders"red: met — same testnear_misses_keep_their_rating(pinned at None)new_secret_paths_escalate_on_read,listed_secret_files_rate_the_data_axis_redtests_red_risk.rs:test_new_destructive_family_requires_confirmation_despite_allow_rule,test_new_secret_path_requires_confirmation_despite_allow_rulecargo test -p ssh-manager-core --lib risk)Tests
Core risk tests (154) and app-logic red-risk tests (32) pass. Counter-proof not run separately: the new tests are positive-rating tests of newly added patterns and fail without them by construction (the patterns are the only source of the rating).
Assumptions
find -deleteuses a regex anchored to thefindcommand word (recommendation of the issue).git commit -m,bash -c "grep …") are in ADR 0167.sgdisk -z(lowercased-Z) is matched as well;sgdisk -zalso destroys the GPT.Spec
updated 0026 (and 0068 secret path list); ADR 0167
Threat model: no change – the lists are documented starting points (§6); only additional patterns, strictly stricter.
Manual test steps
None.
Follow-ups
None.
🤖 Generated with Claude Code
near_misses_keep_their_rating; pipes/echo/git commit/mysqlsh in the families test.